
use RFS_master_data, clear



 	bys call  : egen  Q4size  = xtile(quantity ), nq(4) 

	
		    global vars3 "    N_aver    "

			
  global varIN "Q4size"

  
  foreach jj of global varIN {
  forvalues i = 0/1 {
  foreach j of global vars3 {
  di "`jj'_`j'_`i'"
	 mat ULIQ = J(5,1,1)
 cap drop yy xx*
 gen yy = `j'
 gen xx = size
 gen xxActive = activeZ
 qui winsor2 xx , replace cuts(1 99)
  qui winsor2 yy , replace cuts(1 99)

 cap estimates drop f*
 qui {
 	reghdfe yy  i.`jj'    if xxActive == `i'  , absorb(st0_date#instrumentid   call coun      )    cluster(call   st0_date)
  estimates store ff1
    test 2.`jj'  = 4.`jj' 
    local gg2 = r(p)
    mat ULIQ[1,1] = `gg2'
 
 	reghdfe yy  i.`jj'    if xxActive == `i'  , absorb(st0_date#instrumentid  coun   mm#call  )    cluster(call   st0_date)
  estimates store ff2
    test 2.`jj'  = 4.`jj' 
    local gg2 = r(p)
    mat ULIQ[2,1] = `gg2'
  
 	reghdfe yy  i.`jj'   if xxActive == `i'  , absorb(st0_date#instrumentid    call   st0_date#coun  )    cluster(call   st0_date)
  estimates store ff3
    test 2.`jj'  = 4.`jj' 
    local gg2 = r(p)
    mat ULIQ[3,1] = `gg2'
	
 	reghdfe yy   i.`jj'    if xxActive == `i'  , absorb(st0_date#instrumentid  mm#call st0_date#coun  )    cluster(call   st0_date)
  estimates store ff4
    test 2.`jj'  = 4.`jj' 
    local gg2 = r(p)
    mat ULIQ[4,1] = `gg2'
	
 	reghdfe yy   i.`jj'    if xxActive == `i'  , absorb(st0_date#instrumentid  mm#call st0_date#coun call#coun)    cluster(call   st0_date)
  estimates store ff5
    test 2.`jj'  = 4.`jj' 
    local gg2 = r(p)
    mat ULIQ[5,1] = `gg2'
  
	}
	mat list ULIQ
  esttab ff*     ///
 , star("*" 0.1 "**" 0.05 "***" 0.01) b(%10.3f) t(%10.2f) scalars(N r2) sfmt(%10.3f)   replace
 
   esttab ff* using "RFSnonlinear.tex"     ///
  , star("*" 0.1 "**" 0.05 "***" 0.01) b(%10.3f) t(%10.2f) scalars(N r2) sfmt(%10.3f)   replace
 
  } 
  } 
	}
	 
	 
  